<!-- HTML header for doxygen 1.8.13-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.2"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Connectivity Middleware Utilities Library: JSON parser snippets</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen_style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><a href="http://www.cypress.com/"><img alt="Logo" src="cypress_logo.png"/></a></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Connectivity Middleware Utilities Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.2 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('group__group__json__snippet.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle"><div class="title">JSON parser snippets<div class="ingroups"><a class="el" href="group__group__utils.html">Common middleware utilities</a> &raquo; <a class="el" href="group__json__utils.html">JSON parser utilities</a></div></div></div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"> </div>
<div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;string.h&gt;</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &quot;cy_result.h&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;cy_json_parser.h&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">char</span> str_snippet[] = <span class="stringliteral">&quot; { \&quot;arr\&quot;:[1,2,3], \&quot;bool\&quot;:true, \&quot;url\&quot;: \&quot;https://www.httpbin.org/get\&quot;, \&quot;number\&quot;: 10000 , \&quot;float\&quot;:3.14, \&quot;NULL_VAL\&quot;:null}&quot;</span>;</div>
<div class="line"> </div>
<div class="line"><span class="keyword">static</span> cy_rslt_t parse_json_snippet_callback (<a class="code hl_struct" href="structcy___j_s_o_n__object__t.html">cy_JSON_object_t</a>* json_object, <span class="keywordtype">void</span> *arg )</div>
<div class="line">{</div>
<div class="line">    <span class="keywordflow">switch</span>(json_object-&gt;<a class="code hl_variable" href="structcy___j_s_o_n__object__t.html#aedad7442cc358e4b767a8f8f5faa2760">value_type</a>)</div>
<div class="line">    {</div>
<div class="line">        <span class="keywordflow">case</span> <a class="code hl_enumvalue" href="group__group__json__enums.html#ggae726097fe8827bf417df119581be63daacad69f6dccfcf6c690da769394b16b9b">JSON_STRING_TYPE</a>:</div>
<div class="line">        {</div>
<div class="line">            printf(<span class="stringliteral">&quot;Found a string: %.*s\n&quot;</span>, json_object-&gt;<a class="code hl_variable" href="structcy___j_s_o_n__object__t.html#ae919753ffd0369c83f19a35f7e32ca49">value_length</a>,json_object-&gt;<a class="code hl_variable" href="structcy___j_s_o_n__object__t.html#a34f0f02e90f2e91cfc1c20ced4c15698">value</a> );</div>
<div class="line">            <span class="keywordflow">break</span>;</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">case</span> <a class="code hl_enumvalue" href="group__group__json__enums.html#ggae726097fe8827bf417df119581be63daaacd9e08254e9b6b6f8b85e8ddde8d9fe">JSON_NUMBER_TYPE</a>:</div>
<div class="line">        {</div>
<div class="line">            printf(<span class="stringliteral">&quot;Found a number: %ld\n&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)json_object-&gt;<a class="code hl_variable" href="structcy___j_s_o_n__object__t.html#a581478455266863577d8315930e94716">intval</a>);</div>
<div class="line">            <span class="keywordflow">break</span>;</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">case</span> <a class="code hl_enumvalue" href="group__group__json__enums.html#ggae726097fe8827bf417df119581be63daa777db824b973079813491a5a190a9c48">JSON_FLOAT_TYPE</a>:</div>
<div class="line">        {</div>
<div class="line">            printf(<span class="stringliteral">&quot;Found a float: %f\n&quot;</span>,json_object-&gt;<a class="code hl_variable" href="structcy___j_s_o_n__object__t.html#a6f6fb3d06c83ae12f59aed0db13878aa">floatval</a>);</div>
<div class="line">            <span class="keywordflow">break</span>;</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">case</span> <a class="code hl_enumvalue" href="group__group__json__enums.html#ggae726097fe8827bf417df119581be63daa2c5a6062a415ac9e2865996c2be93e89">JSON_BOOLEAN_TYPE</a>:</div>
<div class="line">        {</div>
<div class="line">            printf(<span class="stringliteral">&quot;Found a boolean: %d\n&quot;</span>,(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)json_object-&gt;<a class="code hl_variable" href="structcy___j_s_o_n__object__t.html#aafe974b9e8c4f5e5c0d3cec73bfd456b">boolval</a>);</div>
<div class="line">            <span class="keywordflow">break</span>;</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">case</span> <a class="code hl_enumvalue" href="group__group__json__enums.html#ggae726097fe8827bf417df119581be63daa0bf81dc857c5db3e3723818c2af3623d">JSON_NULL_TYPE</a>:</div>
<div class="line">        {</div>
<div class="line">            printf(<span class="stringliteral">&quot;Found a NULL type: %.*s\n&quot;</span>, json_object-&gt;<a class="code hl_variable" href="structcy___j_s_o_n__object__t.html#ae919753ffd0369c83f19a35f7e32ca49">value_length</a>,json_object-&gt;<a class="code hl_variable" href="structcy___j_s_o_n__object__t.html#a34f0f02e90f2e91cfc1c20ced4c15698">value</a>);</div>
<div class="line">            <span class="keywordflow">break</span>;</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">case</span> <a class="code hl_enumvalue" href="group__group__json__enums.html#ggae726097fe8827bf417df119581be63daa21924053ad5195dd2cda2b62152c803e">JSON_ARRAY_TYPE</a>:</div>
<div class="line">        {</div>
<div class="line">            printf(<span class="stringliteral">&quot;Found an ARRAY&quot;</span>);</div>
<div class="line">            <span class="keywordflow">break</span>;</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">default</span>:</div>
<div class="line">        {</div>
<div class="line">            <span class="keywordflow">break</span>;</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> json_parser_snippet(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line">    <a class="code hl_function" href="group__group__json__func.html#gaa64abab25df2ef3a207b9c214a1e2b9b">cy_JSON_parser_register_callback</a> ( parse_json_snippet_callback, NULL );</div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">if</span> (<a class="code hl_function" href="group__group__json__func.html#ga3ed706e5f2d8d93295a0d78ea92187e9">cy_JSON_parser</a>(str_snippet , strlen(str_snippet)) == CY_RSLT_SUCCESS) </div>
<div class="line">    {</div>
<div class="line">        printf(<span class="stringliteral">&quot;Successfully parsed the JSON input\n&quot;</span>);</div>
<div class="line">        <span class="keywordflow">return</span> 0;</div>
<div class="line">    } </div>
<div class="line">    <span class="keywordflow">else</span> </div>
<div class="line">    {</div>
<div class="line">        printf(<span class="stringliteral">&quot;Failed to parse the JSON input\n&quot;</span>);</div>
<div class="line">        <span class="keywordflow">return</span> -1;</div>
<div class="line">    }</div>
<div class="line">}</div>
<div class="ttc" id="agroup__group__json__enums_html_ggae726097fe8827bf417df119581be63daa0bf81dc857c5db3e3723818c2af3623d"><div class="ttname"><a href="group__group__json__enums.html#ggae726097fe8827bf417df119581be63daa0bf81dc857c5db3e3723818c2af3623d">JSON_NULL_TYPE</a></div><div class="ttdeci">@ JSON_NULL_TYPE</div><div class="ttdoc">JSON null object.</div><div class="ttdef"><b>Definition:</b> cy_json_parser.h:82</div></div>
<div class="ttc" id="agroup__group__json__enums_html_ggae726097fe8827bf417df119581be63daa21924053ad5195dd2cda2b62152c803e"><div class="ttname"><a href="group__group__json__enums.html#ggae726097fe8827bf417df119581be63daa21924053ad5195dd2cda2b62152c803e">JSON_ARRAY_TYPE</a></div><div class="ttdeci">@ JSON_ARRAY_TYPE</div><div class="ttdoc">JSON array datatype.</div><div class="ttdef"><b>Definition:</b> cy_json_parser.h:79</div></div>
<div class="ttc" id="agroup__group__json__enums_html_ggae726097fe8827bf417df119581be63daa2c5a6062a415ac9e2865996c2be93e89"><div class="ttname"><a href="group__group__json__enums.html#ggae726097fe8827bf417df119581be63daa2c5a6062a415ac9e2865996c2be93e89">JSON_BOOLEAN_TYPE</a></div><div class="ttdeci">@ JSON_BOOLEAN_TYPE</div><div class="ttdoc">JSON boolean datatype.</div><div class="ttdef"><b>Definition:</b> cy_json_parser.h:81</div></div>
<div class="ttc" id="agroup__group__json__enums_html_ggae726097fe8827bf417df119581be63daa777db824b973079813491a5a190a9c48"><div class="ttname"><a href="group__group__json__enums.html#ggae726097fe8827bf417df119581be63daa777db824b973079813491a5a190a9c48">JSON_FLOAT_TYPE</a></div><div class="ttdeci">@ JSON_FLOAT_TYPE</div><div class="ttdoc">JSON float datatype.</div><div class="ttdef"><b>Definition:</b> cy_json_parser.h:78</div></div>
<div class="ttc" id="agroup__group__json__enums_html_ggae726097fe8827bf417df119581be63daaacd9e08254e9b6b6f8b85e8ddde8d9fe"><div class="ttname"><a href="group__group__json__enums.html#ggae726097fe8827bf417df119581be63daaacd9e08254e9b6b6f8b85e8ddde8d9fe">JSON_NUMBER_TYPE</a></div><div class="ttdeci">@ JSON_NUMBER_TYPE</div><div class="ttdoc">JSON integer datatype.</div><div class="ttdef"><b>Definition:</b> cy_json_parser.h:74</div></div>
<div class="ttc" id="agroup__group__json__enums_html_ggae726097fe8827bf417df119581be63daacad69f6dccfcf6c690da769394b16b9b"><div class="ttname"><a href="group__group__json__enums.html#ggae726097fe8827bf417df119581be63daacad69f6dccfcf6c690da769394b16b9b">JSON_STRING_TYPE</a></div><div class="ttdeci">@ JSON_STRING_TYPE</div><div class="ttdoc">JSON string datatype.</div><div class="ttdef"><b>Definition:</b> cy_json_parser.h:73</div></div>
<div class="ttc" id="agroup__group__json__func_html_ga3ed706e5f2d8d93295a0d78ea92187e9"><div class="ttname"><a href="group__group__json__func.html#ga3ed706e5f2d8d93295a0d78ea92187e9">cy_JSON_parser</a></div><div class="ttdeci">cy_rslt_t cy_JSON_parser(const char *json_input, uint32_t input_length)</div><div class="ttdoc">Parse the JSON data.</div></div>
<div class="ttc" id="agroup__group__json__func_html_gaa64abab25df2ef3a207b9c214a1e2b9b"><div class="ttname"><a href="group__group__json__func.html#gaa64abab25df2ef3a207b9c214a1e2b9b">cy_JSON_parser_register_callback</a></div><div class="ttdeci">cy_rslt_t cy_JSON_parser_register_callback(cy_JSON_callback_t json_callback, void *arg)</div><div class="ttdoc">Register callback to be invoked by JSON parser while parsing the JSON data.</div></div>
<div class="ttc" id="astructcy___j_s_o_n__object__t_html"><div class="ttname"><a href="structcy___j_s_o_n__object__t.html">cy_JSON_object_t</a></div><div class="ttdoc">JSON parser object.</div><div class="ttdef"><b>Definition:</b> cy_json_parser.h:101</div></div>
<div class="ttc" id="astructcy___j_s_o_n__object__t_html_a34f0f02e90f2e91cfc1c20ced4c15698"><div class="ttname"><a href="structcy___j_s_o_n__object__t.html#a34f0f02e90f2e91cfc1c20ced4c15698">cy_JSON_object_t::value</a></div><div class="ttdeci">char * value</div><div class="ttdoc">JSON string value parsed.</div><div class="ttdef"><b>Definition:</b> cy_json_parser.h:106</div></div>
<div class="ttc" id="astructcy___j_s_o_n__object__t_html_a581478455266863577d8315930e94716"><div class="ttname"><a href="structcy___j_s_o_n__object__t.html#a581478455266863577d8315930e94716">cy_JSON_object_t::intval</a></div><div class="ttdeci">uint32_t intval</div><div class="ttdoc">JSON integer value parsed.</div><div class="ttdef"><b>Definition:</b> cy_json_parser.h:108</div></div>
<div class="ttc" id="astructcy___j_s_o_n__object__t_html_a6f6fb3d06c83ae12f59aed0db13878aa"><div class="ttname"><a href="structcy___j_s_o_n__object__t.html#a6f6fb3d06c83ae12f59aed0db13878aa">cy_JSON_object_t::floatval</a></div><div class="ttdeci">float floatval</div><div class="ttdoc">JSON float value parsed.</div><div class="ttdef"><b>Definition:</b> cy_json_parser.h:109</div></div>
<div class="ttc" id="astructcy___j_s_o_n__object__t_html_aafe974b9e8c4f5e5c0d3cec73bfd456b"><div class="ttname"><a href="structcy___j_s_o_n__object__t.html#aafe974b9e8c4f5e5c0d3cec73bfd456b">cy_JSON_object_t::boolval</a></div><div class="ttdeci">bool boolval</div><div class="ttdoc">JSON boolean value parsed.</div><div class="ttdef"><b>Definition:</b> cy_json_parser.h:110</div></div>
<div class="ttc" id="astructcy___j_s_o_n__object__t_html_ae919753ffd0369c83f19a35f7e32ca49"><div class="ttname"><a href="structcy___j_s_o_n__object__t.html#ae919753ffd0369c83f19a35f7e32ca49">cy_JSON_object_t::value_length</a></div><div class="ttdeci">uint16_t value_length</div><div class="ttdoc">length of string value parsed</div><div class="ttdef"><b>Definition:</b> cy_json_parser.h:107</div></div>
<div class="ttc" id="astructcy___j_s_o_n__object__t_html_aedad7442cc358e4b767a8f8f5faa2760"><div class="ttname"><a href="structcy___j_s_o_n__object__t.html#aedad7442cc358e4b767a8f8f5faa2760">cy_JSON_object_t::value_type</a></div><div class="ttdeci">cy_JSON_type_t value_type</div><div class="ttdoc">JSON data type of value parsed.</div><div class="ttdef"><b>Definition:</b> cy_json_parser.h:105</div></div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath">
    <ul>
        <li class="footer">
            Generated for <b>Connectivity Middleware Utilities Library</b> by <b>Cypress Semiconductor Corporation</b>.
            All rights reserved.
        </li>
    </ul>
</div>
</body>
</html>
